package com.hyt.it.ogt.controller.ykcj.grade;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.core.util.FastJsonUtil;
import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.annotation.Log;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.enums.BusinessType;
import com.hyt.it.ogt.ykcj.domain.param.ImportQueryParam;
import com.hyt.it.ogt.ykcj.domain.vo.ExcelRowResultVo;
import com.hyt.it.ogt.ykcj.domain.vo.ImportInfoVo;
import com.hyt.it.ogt.ykcj.service.grade.IImportEnterpriseExamineeInfoService;

import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;


/**
 * 企业招聘考生导入信息Controller
 *
 * @author liying
 * @date 2021-11-19
 */
@Api(tags = "grade.19.企业招聘考生导入信息")
@ApiSort(value = 219)
@RestController
@RequestMapping("/enterprise/grade/info")
@Slf4j
public class EnterpriseExamineeInfoImportController extends BaseController {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IImportEnterpriseExamineeInfoService importEnterpriseExamineeInfoService;



    /**
     * 判断当前考试是否有excel在处理
     * @param examId
     * @return
     */
    @ApiOperation(value = "判断当前考试是否有excel在处理")
    @Log(title = "判断当前考试是否有excel在处理")
    @GetMapping("/execute/{examId}")
    public AjaxResult checkExecuteExcelFile(@PathVariable(value = "examId") String examId ) {
        logger.info("## checkExecuteExcelFile queryParamDto:{}",examId);
        Boolean result = importEnterpriseExamineeInfoService.checkExecuteExcelFile(examId);
        return AjaxResult.success(result);
    }


    /**
     * 导入考生数据
     * @param queryParamDto
     * @return
     */
    @ApiOperation(value = "导入考生数据")
    @Log(title = "导入考生数据", businessType = BusinessType.IMPORT)
    @PostMapping("/importtExcelFile")
    public AjaxResult importtExcelFile(@RequestBody ImportQueryParam queryParamDto) {
        logger.info("## importtExcelFile queryParamDto:{}", FastJsonUtil.getBeanToJson(queryParamDto));
        Object[] objects = importEnterpriseExamineeInfoService.importExcelFile(queryParamDto.getFilePath(),queryParamDto.getExamId()
                ,queryParamDto.getSubjectId());
        return new Boolean(objects[0].toString()) ? AjaxResult.success("导入成功", objects[1]) : AjaxResult.error("导入失败", objects[1]);

    }


    /**
     * 获取校验数据列表
     * @param queryParamDto
     * @return
     */
    @ApiOperation(value = "获取校验数据列表" , response = ExcelRowResultVo.class)
    @PostMapping("/queryImport")
    public AjaxResult queryImport(@RequestBody ImportQueryParam queryParamDto) {
        logger.info("## queryImport queryParamDto:{}", FastJsonUtil.getBeanToJson(queryParamDto));
        ExcelRowResultVo excelRowResultVo = importEnterpriseExamineeInfoService.queryExcelImportInfo(queryParamDto);
        return AjaxResult.success( excelRowResultVo);
    }



    /**
     * 导入考生数据
     * @param queryParamDto
     * @return
     */
    @ApiOperation(value = "导入保存考生数据")
    @Log(title = "导入保存考生数据", businessType = BusinessType.IMPORT)
    @PostMapping("/saveExcelFileData")
    public AjaxResult saveExcelFileData(@RequestBody ImportQueryParam queryParamDto) {
        logger.info("## saveExcelFileData queryParamDto:{}", FastJsonUtil.getBeanToJson(queryParamDto));
        Object[] objects = importEnterpriseExamineeInfoService.readExcelFile(queryParamDto.getFilePath(),queryParamDto.getExamId()
                ,queryParamDto.getSubjectId());
        return new Boolean(objects[0].toString()) ? AjaxResult.success("导入成功", objects[1]) : AjaxResult.error("导入失败", objects[1]);

    }


    /**
     * 查询考生导入统计信息
     * @param queryParamDto
     * @return
     */
    @ApiOperation(value = "查询考生导入统计信息" , response = ImportInfoVo.class)
    @Log(title = "查询考生导入统计信息", businessType = BusinessType.IMPORT)
    @PostMapping("/query")
    public AjaxResult queryExcelImportInfo(@RequestBody ImportQueryParam queryParamDto) {
        logger.info("## queryExcelImportInfo queryParamDto:{}",FastJsonUtil.getBeanToJson(queryParamDto));
        ImportInfoVo importInfoDto = importEnterpriseExamineeInfoService.queryExcelImportInfoCount(queryParamDto);
        return AjaxResult.success(importInfoDto);
    }







    /**
     * 下载导入失败数据
     */
    @ApiOperation(value = "下载导入失败数据")
    @Log(title = "下载导入失败数据", businessType = BusinessType.IMPORT)
    @PostMapping("/download")
    public  AjaxResult  downloadData(@RequestBody ImportQueryParam queryParamDto){
        logger.info("## downloadData queryParamDto:{}",FastJsonUtil.getBeanToJson(queryParamDto));

        String  downloadPath = importEnterpriseExamineeInfoService.exportExcelByCondition(queryParamDto);
        return AjaxResult.success("操作成功",downloadPath);
    }





    /**
     * 取消考生导入统计信息
     * @param queryParamDto
     * @return
     */
    @ApiOperation(value = "取消考生导入统计信息" , response = ImportInfoVo.class)
    @Log(title = "取消考生导入统计信息", businessType = BusinessType.IMPORT)
    @PostMapping("/cancel")
    public AjaxResult cancel(@RequestBody ImportQueryParam queryParamDto) {
        logger.info("## cancel queryParamDto:{}",FastJsonUtil.getBeanToJson(queryParamDto));
        Boolean result = importEnterpriseExamineeInfoService.removeExcelImportInfo(queryParamDto);
         return AjaxResult.success(result);
    }



}
